<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.autotab.js"></script>															
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.validate.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/cmxforms.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.metadata.js"></script>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.alphanumeric.pack.js"></script>
<script type="text/javascript">
$.metadata.setType("attr", "validate");
$(document).ready(function() {
	//$('#price').autotab({ target: 'price', format: 'pricea', previous: 'price' });
	$("#form").validate({
		rules:{
				catalog_child: "required",
				catalog_parent: "required",
				price:{
					required: false,
      				digits: false
				},
				shop_name:{
					required: true,
					minlength:3,
					maxlength:50
				},
				name:{
					required: true,
					minlength:3,
					maxlength:100
				},
				address:{
					required:true,
					minlength:12,
					maxlength:255
				},
				image:{
					accept:"gif|jpg|jpeg|pjpeg|png|x-png"
				},
				detail_info:{
					required:false,
					minlength:0
				}
			},
		messages: {
			catalog_child: "Chọn Danh Mục Sản Phẩm",
			catalog_parent: "Chọn Danh Mục Sản Phẩm",
			price:{
				required:"Nhập Giá Sản Phẩm",
				digits:"Giá Sản Phẩm Phải Là Một Số"
			},
			image:{
				accept:"Chỉ Nhập Định Dạng .gif|jpg|jpeg|pjpeg|png|x-png"
			},
			address:{
				required:"Nhập Địa Chỉ Shop",
				minlength:"Địa Chỉ Tối Thiểu 12 Ký Tự",
				maxlength:"Địa Chỉ Tối Thểu 255 Ký Tự"
			},
			shop_name: {
				required:"Nhập Tên Shop",
				minlength:"Tên Sản Phẩm Tối Thiểu 3 Ký Tự Tối Đa 30 Ký Tự",
				maxlength:"Tên Sản Phẩm Tối Thiểu 3 Ký Tự Tối Đa 30 Ký Tự"
			},
			name: {
				required:"Nhập Tên Sản Phẩm",
				minlength:"Tên Sản Phẩm Tối Thiểu 3 Ký Tự Tối Đa 100 Ký Tự",
				maxlength:"Tên Sản Phẩm Tối Thiểu 3 Ký Tự Tối Đa 100 Ký Tự"
			},
			detail_info:{
				required:"Nhập Thông Tim Mô Tả Thông Tin Sản Phẩm",
				minlength:"Thông Tin Sản Phẩm Tối Thiểu 12 Ký Tự"
			}
		}
	});
});
</script>

<style type="text/css">
	.cmxform .upload div  {
		float: left;
		width: 760px;
		margin-left: 30px;
		padding-top: 5px;
	}
	.cmxform .upload .rows .title {
		margin-left:10px;
		border:1px solid black;
		height: 20px;
		width: 710px;
		color:#DA5301;
		font-size:1em;
		font-weight:bold;
		border-color:black;
		clear: both;
		background-color: #DDDFFF;
	}

	.title1 label {
		margin-left:150px;
		border:1px solid black;
		height: 20px;
		width: 710px;
		color:#DA5301;
		font-size:1.2em;
		font-weight:bold;
		background-color: #DDDDDE;
	}

	.cmxform .upload .rows .items {
		margin-left:30px;
		height: 20px;
		width: 600px;
		padding-bottom: 30px;
	}
	.items input{
		margin-left:30px;
		height: 20px;
		width: 500px;
		color: black;
	}

	#image{
		margin-left:30px;
		height: 23px;
		width: 500px;
		color: black;
	}
	.items .error{
		margin-left: 30px;
	}
	.items select{
		width: 500px;
		margin-left:30px;
	}
	.title label {
		margin-left: 100px;
	}

    #payment_sub {
    	display: none;
    }
    .block { display: block; }

</style>

<style type="text/css">
#form { width: 00px; }
#form label { width: 250px; }
#form label.error, #form input.submit { margin-left: 253px; }
#form { width: 670px; }
#form label.error {
	margin-left: 10px;
	width: auto;
	display: inline;
}

#newsletter_topics label.error {
	display: none;
	margin-left: 103px;
}
</style>

<form method="post" name="form" enctype="multipart/form-data" class="cmxform" id="form" action="<?php echo $action; ?>">
<div style="width: 85%; height:100%;  margin-left: 70px;">

<input type="hidden" name="parent_catalog" id="parent_catalog" value="<?php echo $pa_catalog_id; ?>" />
<input type="hidden" name="child_catalog" id="child_catalog" value="<?php echo $cr_catalog_id; ?>" />
<input type="hidden" name="product_id" id="product_id" value="<?php echo $product_id; ?>" />
<input type="hidden" name="old_image" id="old_image" value="<?php echo $old_image; ?>" />

<div class="upload" style="float:left; border: 1px solid #DDDDDD; width: 800px; margin-left: 10px; padding: 10px; background-color: #F6F9FF">
	<div class="rows">
		<div class="" style="padding-bottom: 10px;">
			<b>Mô tả thông tin sản phẩm</b>
		</div>
	</div>
	<div class="rows" style="height: 60px;">
			<div class="title">Chọn hình thức đăng bán
			</div>
			<div class="items" style="clear: both; ">
				<div class="title2" style="clear: both;">
					<?php if($sale_flg == 1){ ?>
						<input type="radio" style="width: 10px;" onclick="doShow();" checked="checked" id="sale_flg1" value="1" name="sale_flg"  /> Đăng Bán
					<?php } else { ?>
						<input type="radio" style="width: 10px;" onclick="doShow();" id="sale_flg1" value="1" name="sale_flg"  /> Đăng Bán
					<?php } ?>
					<?php if($sale_flg == 2){ ?>
						<input type="radio" style="width: 10px" id="sale_flg2" checked="checked" onclick="doHide();" value="2" name="sale_flg"  /> Đăng Mua
					<?php } else { ?>
						<input type="radio" style="width: 10px" id="sale_flg2" onclick="doHide();" value="2" name="sale_flg"  /> Đăng Mua
					<?php } ?>
				</div>
			</div>
		</div>
	<div class="rows">
		<div class="title">
			<label for="product">Tên sản phẩm</label>
		</div>
		<div class="items">
			<input id="name" name="name" size="60" value="<?php echo $productInfo['name']; ?>" />
		</div>
	</div>

	<div class="rows">
		<div class="title">
			<label for="product">Chọn phạm vi đăng bán</label>
		</div>
		<div style="margin-left:90px;float:left; width:210px;">
		  <select name="zone_id" id="zone_id">
              <?php foreach ($areas as $area) { ?>
              		<option value="<?php echo $area['zone_id']; ?>" <?php if( $zone_id == $area['zone_id']) echo "selected";?>  > <?php echo $area['name']; ?></option>
              <?php } ?>
          </select>
		</div>
	</div>

	<div class="rows">
		<div class="title">
			<label for="product">Chọn nghành hàng</label>
		</div>
		<div style="margin-left:90px;float:left; width:210px;">
		  <select name="catalog_parent" id="catalog_parent" onchange="loadChildCatalog(this.value);">
              <?php foreach ($parent_catalog as $catagory) { ?>
              	    <?php if( $pa_catalog_id == $catagory['catalog_id']) { ?>
              			<option value="<?php echo $catagory['catalog_id']; ?>" selected="selected" ><?php echo $catagory['name']; ?></option>
              		<?php } else { ?>
              			<option value="<?php echo $catagory['catalog_id']; ?>"><?php echo $catagory['name']; ?></option>
              		<?php } ?>
              <?php } ?>
          </select>
		</div>
		<div id="catalog_child1" style="float:left; width:210px;" >
			<select disabled="disabled" name="catalog_child" id="catalog_child" >
				<option value="">Chọn danh mục cấp 2</option>
            </select>
		</div>
	</div>
	<div id="product_description" class="rows" style="height: 340px;">
		<div class="title">
			<label for="product">Mô tả sản phẩm</label>
		</div>
		<div class="items" style="clear: both; ">
			<div class="title2" style="clear: both;">
				<label for="product">Hình ảnh</label>
				<img src="<?php echo $image ?>" width="40px;" height="40px"/>
			</div>
			<div class="items" style="clear: both;">
				<input size="81px;" type="file" id="image" name="image"  />
			</div>
			<div class="title2">
				<label for="product">Giá sản phẩm</label>
			</div>
			<div class="titl1" style="clear: both; padding-right: 4px;">
				<input id="price" onkeyup="return auto_currency('price');" value="<?php echo $price; ?>" name="price" style="width:250px;text-align:right" />
				<select name="price_type" id="price_type" style="width: 60px; height: 22px; margin-left: 5px;" >
					<option value="VN" selected="selected">VND</option>
					<option value="USA">USA</option>
				</select>
			</div>
			<div id="pay">
				<div class="title2" style="clear: both;">
					<label for="user">Hình thức thanh toán</label>
				</div>
				<div class="title3">
					<input type="radio" style="width: 15px;" id="payment1" <?php if( $payment_id == 1) echo "checked=checked"; ?> value="1" name="payment"/>
					<label>Xem hàng và trả tiền trực tiếp</label>
				</div>
				<div class="title2" style="clear: both;">
					<input type="radio" style="width: 15px" id="payment2" <?php if( $payment_id == 2) echo "checked=checked"; ?> value="2" name="payment"  /> Chuyển tiền trước nhận hàng sau
				</div>
				<div class="title2" style="clear: both;">
					<input type="radio" style="width: 15px" id="" value="3" <?php if( $payment_id == 3) echo "checked=checked"; ?> name="payment"  /> Đặt hàng trước, 3 ngày sau nhận hàng
				</div>
				<div class="title2" style="clear: both;">
					<input type="radio" style="width: 15px" id="" value="4" <?php if( $payment_id == 4) echo "checked=checked"; ?> name="payment"  /> Xem hàng và trả tiền trực tiếp hoặc chuyển tiền trước nhận hàng sau
				</div>
			</div>
		</div>
	</div>
	<div class="rows" style="height: 300px;">
		<div class="title">
			<label for="user">Chi tiết sản phẩm</label>
		</div>
		<div class="items">
			<textarea id="detail_info" name="detail_info" rows="15" cols="120" style="width: 600px; margin-left: 50px; color: black">
				<?php echo $description; ?>
			</textarea>
		</div>
	</div>
	<div class="rows">
		<div class="items2">
			<input class="button" style="margin-left:10px;" type="submit" value="Đăng Bán"/>
		</div>
	</div>
</div>
</div>
</form>
</body>
</html>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.php.js"></script>

<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript">
var sBasePath = document.location.href.replace(/index\.php.*/, 'catalog/view/javascript/fckeditor/');
var oFCKeditor          = new FCKeditor('detail_info');
	oFCKeditor.BasePath = sBasePath;
	oFCKeditor.Value	   = $("#detail_info").val();
	$("#detail_info").val = "dsfdsfds";
	oFCKeditor.Value	= "";
	oFCKeditor.Width    = '620';
	oFCKeditor.Height   = '250';
	oFCKeditor.ReplaceTextarea();
</script>
<script language="JavaScript" type="text/javascript">
var url = "http://localhost/99xu/index.php?route=upload/product/insert";
formAjax = function () {
   // do an ajax post request
    $.ajax({
       // AJAX-specified URL
       url: url,
       // JSON
       dataType: 'json',
       type: "POST",
       data: $('form#form').formToArray(true),
       /* Handlers */
       // Handle the beforeSend event
       beforeSend: function(){
           return php.beforeSend();
       },
       // Handle the success event
       success: function(data, textStatus){
       	   document.location.href="http://localhost/99xu/index.php?route=product/product&product_id="+data.product_id;
           //return php.success(data, textStatus);
       },
       // Handle the error event
       error: function (xmlEr, typeEr, except) {
           return php.error(xmlEr, typeEr, except);
       },
       // Handle the complete event
       complete: function (XMLHttpRequest, textStatus) {
           return php.complete(XMLHttpRequest, textStatus);
       }
    });
    return false;
}

function doHide(){
	$("#pay").hide();
	$("#product_description").attr("style","height:200px");
}
function doShow(){
	$("#pay").show();
	$("#product_description").attr("style","height:320px");
}

function auto_currency(id){
	var price_type = $('#price_type').val();
	var variable = document.getElementById(id);
	if(price_type == 'VN'){
    	var new_value =  variable.value.replace(/\./g,"");
	}else{
		var new_value =  variable.value;
	}
    variable.style.textAlign = "right";
    variable.value = digit_grouping(new_value);
}
function digit_grouping(nStr){
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
   return x1 + x2;
}

$('#price').numeric({allow:"."});
$('#shop_name').alphanumeric();
var parent_catalog = $('#parent_catalog').val();
var child_catalog  = $('#child_catalog').val();

function loadChildCatalog(value){
	$('#catalog_child1').load('index.php?route=upload/product/childCatalogories&catalog_id=' + value,{ name : this.value });
}
function loadChildCatalog1(value1, value2){
	$('#catalog_child1').load('index.php?route=upload/product/childCatalogories&cr_catalog_id='+ value2 +'&catalog_id=' + value1);
}
loadChildCatalog1(parent_catalog, child_catalog);
</script>